
var XMLRSS = {
    rssUrl : '/CCMVirtual-war/Noticiasccm',
    RSSRequestObject : null,
    
    init : function () {
        XMLRSS.RSSRequest();
    },
    
    GetXmlHttpObject : function() {
        var xmlHttp = null;
        try {
            xmlHttp = new XMLHttpRequest();
        } catch (ex) {
        try {
            xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
        xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
    }
}
return xmlHttp;
},

ReqChange : function() {
    if (typeof(XMLRSS)=="undefined" || !XMLRSS) {
        return;
    }
    
    if (XMLRSS.RSSRequestObject.readyState == 4) {
        if (XMLRSS.RSSRequestObject.responseText.indexOf('invalid') == -1) {
            var node = XMLRSS.RSSRequestObject.responseXML.documentElement;
            
            if (node !== null) {
                var channel = node;
                
                var title = "Noticias";
                var link = "#";
                
                var content = '<ul>';
                
                var items = XMLRSS.RSSRequestObject.responseXML.getElementsByTagName('noticia');
                
                for (var n = 0; n < items.length; n++) {
                    var itemTitle = items[n].getElementsByTagName('titulo').item(0).firstChild.data;
                    var itemPubDate = items[n].getElementsByTagName('fecha').item(0).firstChild.data;
                    var itemLink = "#";
                    var itemDescription = items[n].getElementsByTagName('texto').item(0).firstChild.data;
                    
                    content += '<div id="entry" style="width:700">';
                    content += '<div class="entryHeader"><img id="maxmin' + n + '" src="/CCMVirtual-war/img/max.gif" onClick="XMLRSS.HideShowN(\'' + n + '\')" /><a  alt="" title="' + itemPubDate + '" href="#">' + itemTitle.substring(0, 33) + '...</a></div>';
                    content += '<div id="entry' + n + '" style="display:none">';
                    content += '<div class="entryBody"><div class="entryBodyText">' + itemDescription.substring(0, 25) + '...</div></div>';
                    content += '</div></div>';
                }
                
                content += '</ul>';
                document.getElementById("blog").innerHTML = content;
                
                document.getElementById("status").innerHTML = "Done.";
                XMLRSS.HideShow('status');
            } else {
            document.getElementById("status").innerHTML = "<div class=error>Invalid URL.<div>";
        }
    } else {
    document.getElementById("status").innerHTML = "<div class=error>Error requesting data.<div>";
}
}
},

RSSRequest : function() {
    XMLRSS.HideShow('status');
    document.getElementById("status").innerHTML = "Requesting data ...";
    
    XMLRSS.RSSRequestObject.open("GET", XMLRSS.rssUrl , true);
    
    XMLRSS.RSSRequestObject.onreadystatechange = XMLRSS.ReqChange;
    
    XMLRSS.RSSRequestObject.send(null);
    
},

update_timer : function() {
    XMLRSS.RSSRequest();
},

HideShow : function(id) {
    var el = document.getElementById(id);
    
    if (el.style.display == "none") {
        el.style.display = '';
    } else {
    el.style.display = 'none';
}
},

HideShowN : function(id) {
    var el = document.getElementById("entry" + id);
    var img = document.getElementById("maxmin" + id);
    
    if (el === null) {
        document.getElementById("entry" + id);
    }
    
    if (el.style.display == "none") {
        el.style.display = '';
        if (img) {
            img.src = "/CCMVirtual-war/img/min.gif";
        }
    } else {
    el.style.display = 'none';
    if (img) {
        img.src = "/CCMVirtual-war/img/max.gif";
    }
}
}
};